package com.ilink.dataanalysis.controller;

import com.ilink.dataanalysis.entity.VO.CommonResponseVO;
import com.ilink.dataanalysis.service.TbUserService;
import com.ilink.ilinkcommon.log.method.MethodLog;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import static org.springframework.web.bind.annotation.RequestMethod.POST;

@Slf4j
@RestController
@RequestMapping("/dataanalysis")
@RequiredArgsConstructor
public class DataAnalysisController {

    private final TbUserService tbUserService;

    @MethodLog(value = "研创数据大屏返回已覆盖学校")
    @RequestMapping(value = "/getDifferentSchoolCount", method = POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public String getDifferentSchoolCount(@RequestBody (required = false)String filter) {
        // filter 就是字符串形式的 json，需要使用 Jackson 等库解析为对象来使用
        try {
            return new CommonResponseVO(tbUserService.getDifferentSchoolCount()).toString();
        } catch(Exception e) {
            return CommonResponseVO.error(e);
        }
    }

    @MethodLog(value = "研创数据大屏返回已报名人数")
    @RequestMapping(value = "/getStudentCount", method = POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public String getStudentCount(@RequestBody (required = false)String filter) {
        // filter 就是字符串形式的 json，需要使用 Jackson 等库解析为对象来使用
        try {
            return new CommonResponseVO(tbUserService.getStudentCount()).toString();
        } catch(Exception e) {
            return CommonResponseVO.error(e);
        }
    }

    @MethodLog(value = "研创数据大屏返回已覆盖专业")
    @RequestMapping(value = "/getDifferentMajorCount", method = POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public String getDifferentMajorCount(@RequestBody (required = false)String filter) {
        // filter 就是字符串形式的 json，需要使用 Jackson 等库解析为对象来使用
        try {
            return new CommonResponseVO(tbUserService.getDifferentMajorCount()).toString();
        } catch(Exception e) {
            return CommonResponseVO.error(e);
        }
    }

    @MethodLog(value = "研创数据大屏专业分布")
    @RequestMapping(value = "/getMajorDistribution", method = POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public String getMajorDistribution(@RequestBody (required = false)String filter) {
        // filter 就是字符串形式的 json，需要使用 Jackson 等库解析为对象来使用
        try {
            return new CommonResponseVO(tbUserService.getMajorAndCount()).toString();
        } catch(Exception e) {
            return CommonResponseVO.error(e);
        }
    }

    @MethodLog(value = "研创数据大屏在校生统计")
    @RequestMapping(value = "/getStudentInfo", method = POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public String getStudentInfo(@RequestBody (required = false)String filter) {
        // filter 就是字符串形式的 json，需要使用 Jackson 等库解析为对象来使用
        try {
            return new CommonResponseVO(tbUserService.getEnrollmentStatistics()).toString();
        } catch(Exception e) {
            return CommonResponseVO.error(e);
        }
    }

    @MethodLog(value = "研创数据大屏学校地图")
    @RequestMapping(value = "/getMapInfo", method = POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public String getMapInfo(@RequestBody (required = false)String filter) {
        // filter 就是字符串形式的 json，需要使用 Jackson 等库解析为对象来使用
        try {
            return new CommonResponseVO(tbUserService.getSchoolAndItsStudent()).toString();
        } catch(Exception e) {
            return CommonResponseVO.error(e);
        }
    }

    @MethodLog(value = "研创数据大屏平台用户统计")
    @RequestMapping(value = "/getUserStatistics", method = POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public String getUserStatistics(@RequestBody (required = false)String filter) {
        // filter 就是字符串形式的 json，需要使用 Jackson 等库解析为对象来使用
        try {
            return new CommonResponseVO(tbUserService.getUserStatistics()).toString();
        } catch(Exception e) {
            return CommonResponseVO.error(e);
        }
    }

    @MethodLog(value = "研创数据大屏平台资源访问")
    @RequestMapping(value = "/getResourceAccessTime", method = POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public String getResourceAccessTime(@RequestBody (required = false)String filter) {
        // filter 就是字符串形式的 json，需要使用 Jackson 等库解析为对象来使用
        try {
            return new CommonResponseVO(tbUserService.getResourceAccessTime()).toString();
        } catch(Exception e) {
            return CommonResponseVO.error(e);
        }
    }
}
